package cn.gmcx.lazy.izze.Task;

import cn.gmcx.lazy.izze.components.WebSocketServer;
import cn.gmcx.lazy.izze.pojo.WebsocketPJ;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Slf4j
@Component
@EnableScheduling
@EnableAsync
public class MyTask {
    @Autowired
    private WebSocketServer webSocketServer;
    @Async
//    @Scheduled(fixedRate = 30000)
    @Scheduled(cron = ("0 * * * * *"))
    public void websocketTask(){
        WebsocketPJ websocketPJ = new WebsocketPJ();
        websocketPJ.setType(0);
        JSONObject json = JSONUtil.parseObj(websocketPJ,false);
        webSocketServer.sendAll(String.valueOf(json));
        log.info(String.valueOf(json));
    }
}
